package com.suse.service.admin.edu.controller;

import com.suse.common.config.response.R;
import com.suse.service.admin.edu.model.param.TeacherQueryParam;
import com.suse.service.admin.edu.model.param.TeacherSaveParam;
import com.suse.service.admin.edu.model.param.TeacherUpdateParam;
import com.suse.service.admin.edu.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * <p>
 * 讲师 前端控制器
 * </p>
 *
 * @author 辜玉彬
 * @since 2022-08-09
 */
@Api(tags = "讲师接口")
@RestController
@RequestMapping("/teacher")
@CrossOrigin
public class TeacherController {

    @Resource
    private TeacherService teacherService;

    @ApiOperation(value = "获取讲师列表")
    @GetMapping("/list")
    public R getTeacherList() {
        return teacherService.getTeacherList();
    }

    @ApiOperation(value = "获取讲师表格(分页)")
    @PostMapping("/table")
    public R getTeacherTable(@RequestBody TeacherQueryParam teacherQueryParam) {
        return teacherService.getTeacherTable(teacherQueryParam);
    }

    @ApiOperation(value = "获取讲师下拉列表")
    @GetMapping("/select")
    public R getTeacherSelect() {
        return teacherService.getTeacherSelect();
    }

    @ApiOperation(value = "删除讲师(逻辑删除)")
    @DeleteMapping("/remove/{id}")
    public R removeTeacher(@PathVariable("id") String id) {
        return teacherService.removeTeacher(id);
    }

    @ApiOperation(value = "批量删除讲师(逻辑删除)")
    @DeleteMapping("/removeBatch")
    public R removeBatchTeacher(@RequestBody String[] ids) {
        return teacherService.removeBatchTeacher(ids);
    }

    @ApiOperation(value = "添加讲师")
    @PostMapping("/save")
    public R save(@Valid @RequestBody TeacherSaveParam teacherSaveParam) {
        return teacherService.save(teacherSaveParam);
    }

    @ApiOperation(value = "修改讲师")
    @PostMapping("/update")
    public R update(@Valid @RequestBody TeacherUpdateParam teacherUpdateParam) {
        return teacherService.update(teacherUpdateParam);
    }

    @ApiOperation(value = "通过关键字获取讲师名称列表")
    @GetMapping("/name-list/{key}")
    public R getTeacherNameListByKey(@ApiParam(value = "关键字") @PathVariable("key") String key) {
        return teacherService.getTeacherNameListByKey(key);
    }

    @ApiOperation(value = "通过ID获取讲师信息和讲师课程")
    @GetMapping("/info-and-course/{id}")
    public R getTeacherInfoAndCourseById(@PathVariable("id") String id) {
        return teacherService.getTeacherInfoAndCourseById(id);
    }

}

